#include <CountDownLatch.h>

namespace AsyncLogger {

	void CountDownLatch::wait()
	{
		std::unique_lock<std::mutex> lock(mutex_);
		if (count_ > 0) {
			condition_.wait(lock, [=]() {return count_ == 0; });
		}
	}

	void CountDownLatch::countDown()
	{
		std::lock_guard<std::mutex> lock(mutex_);
		--count_;
		if (count_ == 0) {
			condition_.notify_all();
		}
	}
}
